﻿using System;
using System.IO.Ports;


namespace ToolsetL.Modle
{
    public class SerialPortConfiguration
    {
        public string COM;

        public int BaudRate;

        public int Databits;

        public StopBits Stopbits;

        public Parity Parity;

        public static SerialPortConfiguration GetSerialPortConfiguration(string value)
        {
            var result = new SerialPortConfiguration();
            if (string.IsNullOrWhiteSpace(value))
            {
                return result;
            }
            var data = value.Split(',');
            if (data.Length < 5)
            {
                return result;
            }
            try
            {
                result.COM = data[0];
                result.BaudRate = Convert.ToInt32(data[1]);
                result.Parity = (Parity)Convert.ToInt32(data[2]);
                result.Databits = Convert.ToInt32(data[3]);
                result.Stopbits = (StopBits)Convert.ToInt32(data[2]);
                return result;
            }
            catch (Exception)
            {
                return result;
            }
        }
    }
}
